package com.dayuanit.dy14.atm.demo2.dy14atmcommon.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {

    public static String dateToString(Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return simpleDateFormat.format(date);
    }

    public static Date stringToDate(String date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return simpleDateFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static Date add(int number, int unit) {
        Calendar cal = Calendar.getInstance();
        cal.add(unit, number);
        return cal.getTime();
    }

    public static void main(String[] args) {
        System.out.println(DateUtils.dateToString(new Date()));
        System.out.println(add(60, Calendar.SECOND));
    }
}
